const http = require('http')
const fs = require('fs');
const hostname = '127.0.0.1'
const port = 3000

const server = http.createServer( (req,res)=>{
    res.statusCode = 200
    res.setHeader('Content-Type', 'text/html;charset=utf-8')
    //读取index.html文件
    fs.readFile('index.html','utf-8',(err,data)=>{
        if(err){
            res.end('读取失败')
            return;
        }
        res.end( data)
    })
})

server.listen(port, hostname, () => {
    console.log(`Server running at http://${hostname}:${port}/`)
})